package core;

import java.awt.image.BufferedImage;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import map.CollisionDetector;
import map.Item;
import map.ItemCategory;
import map.Level;
import map.Lightmap;
import map.TileType;
import network.Client;
import objects.Enemy;
import objects.EnemyType;
import objects.Player;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.TrueTypeFont;

import tools.Coordinate;
import tools.Direction;
import tools.ImageFactory;
import audio.SoundEffect;
import audio.SoundFactory;
import battle.BattleResult;
import battle.BattleResultType;

public class Game extends BasicGame {

	private Level currentLevel;

	// Graphics
	List<Image> listTileGraphics;
	List<Image> listItemGraphics;
	List<Image> listCharacterGraphics;
	List<Image> listEquipGraphics;
	List<Image> listUiGraphics;

	private Music music = null;

	// MapDrawConfig
	private int tileSize = 32;
	private int xOffset = 50;
	private int yOffset = 50;

	private boolean moving = false;
	private Direction movingDir;
	private int moveDelta = 0;

	private Client client;

	private int destX;
	private int destY;

	private int mouseX;
	private int mouseY;

	private String combatMsg;
	private int combatMsgDelta;
	private Font combatMsgFont;
	
	private Font levelFont;

	private boolean showInventory = false;

	private boolean victorySoundPlayed = false;

	// new Stuff
	private LinkedList<Player> listPlayers;
	private Player player;

	private int frameWidth = 0;
	private int frameHeight = 0;

	private boolean debug = false;

	private boolean init = true;

	private boolean mapView = false;

	private int cameraX = 0;
	private int cameraY = 0;
	private int cameraViewSize = 17;

	// inventory attributes
	private int inventoryX;
	private int inventoryY;
	private int selectedItemIndex;

	public Game(String title, int frameWidth, int frameHeight) {
		super(title);
		this.frameWidth = frameWidth;
		this.frameHeight = frameHeight;
	}

	private void loadImages() {

		listTileGraphics = ImageFactory.getInstance().splitImg("lib/img/tiles.png", tileSize, tileSize);
		listCharacterGraphics = ImageFactory.getInstance().splitImg("lib/img/characters.png", tileSize, tileSize);
		listEquipGraphics = ImageFactory.getInstance().splitImg("lib/img/equip.png", tileSize, tileSize);
		listItemGraphics = ImageFactory.getInstance().splitImg("lib/img/items.png", tileSize, tileSize);
		listUiGraphics = ImageFactory.getInstance().splitImg("lib/img/ui.png", tileSize, tileSize);
	}

	@Override
	public void init(GameContainer arg0) throws SlickException {

		loadImages();

		this.inventoryX = 0;
		this.inventoryY = 0;
		this.selectedItemIndex = -1;

		combatMsgFont = new TrueTypeFont(new java.awt.Font("Verdana", 0, 9), false);
		levelFont = new TrueTypeFont(new java.awt.Font("Verdana", 1, 24), false);

		combatMsgDelta = 0;
		combatMsg = "";

		int userId = new Random().nextInt(100000);

		// init new stuff
		listPlayers = new LinkedList<Player>();
		this.player = new Player(new Coordinate(1, 1), "Player" + new Random().nextInt(), userId, 0);
		//

		/*
		 * GENERAL_FLOOR(0, true), CARPET(1, true), HOLE(2, false), WALL(3,
		 * false), DOOR_OPENED(4, true), DOOR_CLOSED_UP(5, false),
		 * DOOR_CLOSED_DOWN(6, false);
		 */

		// start own client
		this.client = new Client("192.168.178.6", 1234, new Random().nextInt(1000) + 1234, this.player, userId);
		this.currentLevel = client.loginAction(this.player);
		this.currentLevel.setListEnemies(client.getListEnemies());
		destX = 0;
		destY = 0;

		xOffset = (frameWidth / 2) - (cameraViewSize / 2 + 1) * tileSize;
		yOffset = (frameHeight / 2) - (cameraViewSize / 2 + 1) * tileSize;

		calcCameraPosition();
		calcLight(this.player.getCoord().getX(), this.player.getCoord().getY());

		// startTownMusic();

	}

	@Override
	public void update(GameContainer gc, int delta) throws SlickException {
		Input input = gc.getInput();

		if (client != null) {

			if (this.client.isRoomUpdate()) {
				if (this.client.getServerLevel() != null) {
					System.out.println("there is a new room!");
					this.player.setReady(false);
					this.client.setRoomUpdate(false);
					this.currentLevel = this.client.getServerLevel();
					victorySoundPlayed = false;
					combatMsg = "";
					combatMsgDelta = 0;
					for (Player listPlayer : this.client.getListPlayers()) {
						if (listPlayer.getUserId() == this.client.getClientId()) {
							this.player.setCoord(listPlayer.getCoord());
							break;
						}
					}
					this.player.setCurLevelIndex(this.client.getPlayer().getCurLevelIndex());
					calcLight(this.player.getCoord().getX(), this.player.getCoord().getY());
					calcCameraPosition();

					/*
					 * if(this.player.getCurLevelIndex() == 0) {
					 * startTownMusic(); } else { this.music.stop(); }
					 */

				}
			}
			this.listPlayers = client.getListPlayers();
			this.player = client.getPlayer();
			if (client.getListEnemies() != null) {
				this.currentLevel.setListEnemies(client.getListEnemies());
				if (this.currentLevel.getListEnemies().size() == 0) {
					// this.currentRoom.getTiles()[9][0]
					// .setTileType(TileType.GENERAL_FLOOR);
					// this.combatMsg = "VICTORY!";
					if (!victorySoundPlayed) {
						SoundFactory.getInstance().playSoundEffect(SoundEffect.FANFARE);
						victorySoundPlayed = true;
					}
				}
			}
		}

		if (this.player.getCurHp() <= 0) {
			this.client.readyAction(player, 0);
			this.player.setCurHp(this.player.getMaxHp());
		}

		if (!combatMsg.equals("")) {
			combatMsgDelta += delta;
			if (combatMsgDelta > 750) {
				combatMsg = "";
				combatMsgDelta = 0;
			}
		}

		if (showInventory) {
			// Inventory Movement

			if (input.isKeyPressed(Input.KEY_LEFT)) {
				calcInventoryMovement(Direction.LEFT);
			} else if (input.isKeyPressed(Input.KEY_RIGHT)) {
				calcInventoryMovement(Direction.RIGHT);
			} else if (input.isKeyPressed(Input.KEY_DOWN)) {
				calcInventoryMovement(Direction.DOWN);
			} else if (input.isKeyPressed(Input.KEY_UP)) {
				calcInventoryMovement(Direction.UP);
			} else if (input.isKeyPressed(Input.KEY_I)) {
				showInventory = false;
			} else if (input.isKeyPressed(Input.KEY_SPACE)) {

				if (this.selectedItemIndex != -1) {
					if (this.selectedItemIndex != this.player.getListItems().size()) {
						if (this.player.getListItems().get(this.selectedItemIndex) != null) {
							ItemCategory itemCategory = this.player.getListItems().get(this.selectedItemIndex).getItemType().getItemCategory();

							if (itemCategory == ItemCategory.WEAPON) {
								if (this.player.getListItems().get(this.selectedItemIndex).isInUse()) {
									this.player.getListItems().get(this.selectedItemIndex).setInUse(false);
									this.player.setItemWeapon(null);
								} else {
									if (this.player.getItemWeapon() != null) {
										this.player.getItemWeapon().setInUse(false);
									}
									this.player.setItemWeapon(this.player.getListItems().get(this.selectedItemIndex));
									this.player.getItemWeapon().setInUse(true);
								}
							} else if (itemCategory == ItemCategory.HELMET) {
								if (this.player.getListItems().get(this.selectedItemIndex).isInUse()) {
									this.player.getListItems().get(this.selectedItemIndex).setInUse(false);
									this.player.setItemHelmet(null);
								} else {
									if (this.player.getItemHelmet() != null) {
										this.player.getItemHelmet().setInUse(false);
									}
									this.player.setItemHelmet(this.player.getListItems().get(this.selectedItemIndex));
									this.player.getItemHelmet().setInUse(true);
								}
							} else if (itemCategory == ItemCategory.SHIELD) {
								if (this.player.getListItems().get(this.selectedItemIndex).isInUse()) {
									this.player.getListItems().get(this.selectedItemIndex).setInUse(false);
									this.player.setItemShield(null);
								} else {
									if (this.player.getItemShield() != null) {
										this.player.getItemShield().setInUse(false);
									}
									this.player.setItemShield(this.player.getListItems().get(this.selectedItemIndex));
									this.player.getItemShield().setInUse(true);
								}
							} else if (itemCategory == ItemCategory.ARMOR) {
								if (this.player.getListItems().get(this.selectedItemIndex).isInUse()) {
									this.player.getListItems().get(this.selectedItemIndex).setInUse(false);
									this.player.setItemArmor(null);
								} else {
									if (this.player.getItemArmor() != null) {
										this.player.getItemArmor().setInUse(false);
									}
									this.player.setItemArmor(this.player.getListItems().get(this.selectedItemIndex));
									this.player.getItemArmor().setInUse(true);
								}
							} else if (itemCategory == ItemCategory.CONSUMEABLE) {
								// should be saved in the item
								this.player.setCurHp(this.player.getCurHp() + 10);
								this.player.getListItems().remove(this.selectedItemIndex);

							}

						}
					}
				}

			}

		} else {
			if (!moving) {
				// Game Movement
				mouseX = (int) (input.getMouseX() - xOffset) / tileSize;
				mouseY = (int) (input.getMouseY() - yOffset) / tileSize;

				if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
				/*	moving = true;
					if (mouseX > this.player.getCoord().getX()) {
						movingDir = Direction.RIGHT;
					} else if (mouseX < this.player.getCoord().getX()) {
						movingDir = Direction.LEFT;
					} else if (mouseY > this.player.getCoord().getY()) {
						movingDir = Direction.DOWN;
					} else if (mouseY < this.player.getCoord().getY()) {
						movingDir = Direction.UP;
					}*/
				} else {

					if (input.isKeyDown(Input.KEY_RIGHT)) {
						if (!moving) {
							moving = true;
							movingDir = Direction.RIGHT;
						}
					} else if (input.isKeyDown(Input.KEY_LEFT)) {
						if (!moving) {
							moving = true;
							movingDir = Direction.LEFT;
						}
					} else if (input.isKeyDown(Input.KEY_UP)) {
						if (!moving) {
							moving = true;
							movingDir = Direction.UP;
						}
					} else if (input.isKeyDown(Input.KEY_DOWN)) {
						if (!moving) {
							moving = true;
							movingDir = Direction.DOWN;
						}
					} else if (input.isKeyPressed(Input.KEY_SPACE)) {

						if (this.currentLevel.getTiles()[this.player.getCoord().getX()][this.player.getCoord().getY()].getTileType() == TileType.STAIRS_DOWN) {
							this.client.readyAction(player, this.player.getCurLevelIndex() + 1);
						} else if (this.currentLevel.getTiles()[this.player.getCoord().getX()][this.player.getCoord().getY()].getTileType() == TileType.STAIRS_UP) {
							this.client.readyAction(player, this.player.getCurLevelIndex() - 1);
						} else {
							this.player.setReady(false);

							for (int i = 0; i < client.getListItems().size(); i++) {
								if (this.client.getListItems().get(i).getCoord().getX() == this.player.getCoord().getX()
										&& this.client.getListItems().get(i).getCoord().getY() == this.player.getCoord().getY()) {
									this.player.getListItems().add(this.client.getListItems().get(i));
									this.client.getListItems().remove(i);
									this.client.itemPickUpAction(this.player);
									break;
								}
							}
						}

					} else if (input.isKeyDown(Input.KEY_A)) {
						this.player.setCurHp(this.player.getCurHp() + 1);
					} else if (input.isKeyDown(Input.KEY_D)) {
						this.player.setCurHp(this.player.getCurHp() - 1);
					} else if (input.isKeyPressed(Input.KEY_F1)) {
						if (debug) {
							debug = false;
						} else {
							debug = true;
						}
					} else if (input.isKeyPressed(Input.KEY_M)) {
						if (mapView) {
							mapView = false;
							this.tileSize = 32;
							this.cameraViewSize = 17;
						} else {
							mapView = true;
							this.tileSize = 8;
							this.cameraViewSize = 47;
						}
						loadImages();
					} else if (input.isKeyPressed(Input.KEY_R)) {
						this.player.setReady(true);
						this.client.moveAction(this.player, createLightmap());
					} else if (input.isKeyPressed(Input.KEY_I)) {

						this.showInventory = true;
						input.clearKeyPressedRecord();
						inventoryX = 0;
						inventoryY = 0;
						calcInventoryMovement(null);
					}
				}
			} else if (moveDelta > 150) {
				movePlayer(movingDir);
			} else {
				moveDelta += delta;
			}
		}

	}

	private Lightmap createLightmap() {

		Lightmap lightmap = new Lightmap(this.client.getClientId(), this.player.getCurLevelIndex(), this.currentLevel.getTiles().length, this.currentLevel
				.getTiles()[0].length);

		for (int x = 0; x < this.currentLevel.getTiles().length; x++) {
			for (int y = 0; y < this.currentLevel.getTiles()[x].length; y++) {
				if (this.currentLevel.getTiles()[x][y] != null) {
					if (!this.currentLevel.getTiles()[x][y].isHidden()) {
						// System.out.println("create lightmap :: true");
						lightmap.getLightTiles()[x][y] = true;
					}
				}

			}
		}

		return lightmap;
	}

	private void calcInventoryMovement(Direction dir) {
		// inventory cursor movement
		if (dir == Direction.RIGHT) {
			this.inventoryX++;
		} else if (dir == Direction.LEFT) {
			this.inventoryX--;
		} else if (dir == Direction.DOWN) {
			this.inventoryY++;
		} else if (dir == Direction.UP) {
			this.inventoryY--;
		}

		this.selectedItemIndex = -1;
		int selectedItemSlot = (inventoryX * 10) + inventoryY;
		System.out.println(selectedItemSlot);

		if (inventoryX >= 0 && inventoryY >= 0) {
			if (this.player.getListItems().size() > selectedItemSlot) {
				if (this.player.getListItems().get(selectedItemSlot) != null) {
					selectedItemIndex = selectedItemSlot;

				}
			}
		}

		moving = false;
	}

	private void movePlayer(Direction dir) {
		destX = this.player.getCoord().getX();
		destY = this.player.getCoord().getY();
		if (dir == Direction.RIGHT) {
			destX++;
		} else if (dir == Direction.LEFT) {
			destX--;
		} else if (dir == Direction.DOWN) {
			destY++;
		} else if (dir == Direction.UP) {
			destY--;
		}

		calcLight(destX, destY);

		if (CollisionDetector.getInstance().isAccessible(this.currentLevel, new Coordinate(destX, destY))) {

			if (!CollisionDetector.getInstance().isEnemyAtPos(this.currentLevel, new Coordinate(destX, destY))) {
				this.player.getCoord().setX(destX);
				this.player.getCoord().setY(destY);
				calcCameraPosition();
				this.client.moveAction(this.player, createLightmap());
				SoundFactory.getInstance().playSoundEffect(SoundEffect.WALK);
			} else {
				// attackAction
				int xSave = this.player.getCoord().getX();
				int ySave = this.player.getCoord().getY();
				this.player.getCoord().setX(destX);
				this.player.getCoord().setY(destY);

				BattleResult battleResult = this.client.attackAction(this.player);
				if (battleResult != null) {
					if (battleResult.getBattleResultType() == BattleResultType.HIT) {
						System.out.println("hit!");
						SoundFactory.getInstance().playSoundEffect(SoundEffect.HIT);
					} else if (battleResult.getBattleResultType() == BattleResultType.MISS) {
						System.out.println("miss!");
						SoundFactory.getInstance().playSoundEffect(SoundEffect.MISS);
					} else if (battleResult.getBattleResultType() == BattleResultType.BLOCK) {
						System.out.println("block!");
						SoundFactory.getInstance().playSoundEffect(SoundEffect.BLOCK);
					} else if (battleResult.getBattleResultType() == BattleResultType.DEATH) {
						System.out.println("Death!");
						SoundFactory.getInstance().playSoundEffect(SoundEffect.DEATH);
					}
					if (this.player.setExperience(this.player.getExperience() + battleResult.getExperience())) {

						combatMsg = "Lvl up!";

					} else {
						combatMsg = battleResult.getBattleResultType().getCombatMsg();
					}
				}
				this.player.getCoord().setX(xSave);
				this.player.getCoord().setY(ySave);
				calcCameraPosition();

			}

		}

		moving = false;
		moveDelta = moveDelta - 150;

	}

	private void calcCameraPosition() {
		if (this.player.getCoord().getX() >= (cameraViewSize - 1) / 2) {
			cameraX = this.player.getCoord().getX() - (cameraViewSize - 1) / 2;
		} else {
			cameraX = 0;
		}
		if (this.player.getCoord().getY() >= (cameraViewSize - 1) / 2) {
			cameraY = this.player.getCoord().getY() - (cameraViewSize - 1) / 2;
		} else {
			cameraY = 0;
		}
	}

	private void calcLight(int x, int y) {

		int offset = (this.player.getSightRadius() - 1) / 2;

		x = x - offset;
		y = y - offset;

		for (int i = 0; i < this.player.getSightRadius(); i++) {

			if (x + i >= 0 && x + i < currentLevel.getTiles().length) {
				for (int n = 0; n < this.player.getSightRadius(); n++) {

					if (y + n >= 0 && y + n < currentLevel.getTiles()[i].length) {

						if (currentLevel.getTiles()[x + i][y + n] != null) {
							currentLevel.getTiles()[x + i][y + n].setHidden(false);
						}
					}

				}
			}

		}

	}

	private void startTownMusic() {
		try {
			music = new Music("lib/music/town.ogg");
			music.setVolume((float) 0.1);
			music.loop();
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void render(GameContainer arg0, Graphics g) throws SlickException {

		if (currentLevel != null && !showInventory) {

			for (int x = cameraX; x < cameraX + cameraViewSize && x < currentLevel.getTiles().length; x++) {
				for (int y = cameraY; y < cameraY + cameraViewSize && y < currentLevel.getTiles()[x].length; y++) {

					int drawX = (x - cameraX) * tileSize + xOffset;
					int drawY = (y - cameraY) * tileSize + yOffset;

					if (currentLevel.getTiles()[x][y] != null) {
						// map
						if (!currentLevel.getTiles()[x][y].isHidden()) {
							g.drawImage(listTileGraphics.get(currentLevel.getTiles()[x][y].getTileType().getSpriteIndex()), drawX, drawY);
						}
					}
					g.setColor(Color.darkGray);
					/*
					 * g.drawRect(x * tileSize + xOffset, y * tileSize +
					 * yOffset, tileSize, tileSize);
					 */

				}
			}

			for (int x = cameraX; x < cameraX + cameraViewSize && x < currentLevel.getTiles().length; x++) {
				for (int y = cameraY; y < cameraY + cameraViewSize && y < currentLevel.getTiles()[x].length; y++) {

					if (currentLevel.getTiles()[x][y] != null) {
						if (!currentLevel.getTiles()[x][y].isHidden()) {

							int drawX = (x - cameraX) * tileSize + xOffset;
							int drawY = (y - cameraY) * tileSize + yOffset;

							// Items
							if (this.client.getListItems() != null) {
								for (Item item : this.client.getListItems()) {
									if (item.getCoord().getX() == x && item.getCoord().getY() == y) {
										g.drawImage(listItemGraphics.get(item.getItemType().getSpriteId()), drawX, drawY);
									}
								}
							}

							// Enemies
							if (currentLevel.getListEnemies() != null) {
								for (Enemy enemy : currentLevel.getListEnemies()) {
									if (enemy.getxPosition() == x && enemy.getyPosition() == y) {

										g.drawImage(listCharacterGraphics.get(enemy.getEnemyType().getSpriteId()), drawX, drawY);

										// health
										g.setColor(Color.black);
										g.fillRect(drawX - 1, drawY - 5, tileSize + 2, 5);
										g.setColor(Color.red);
										g.fillRect(drawX, drawY - 4, (tileSize * enemy.getCurHp()) / enemy.getMaxHp(), 3);

									}
								}
							}
							// Other Players
							for (Player otherPlayer : this.listPlayers) {
								if (otherPlayer.getCoord().getX() == x && otherPlayer.getCoord().getY() == y) {
									if (otherPlayer.getUserId() != player.getUserId() && otherPlayer.getCurLevelIndex() == this.player.getCurLevelIndex()) {

										g.drawImage(listCharacterGraphics.get(otherPlayer.getSpriteIndex()), drawX, drawY);
									}
								}
							}

							// Player
							if (this.player.getCoord().getX() == x && this.player.getCoord().getY() == y) {

								g.drawImage(listCharacterGraphics.get(this.player.getSpriteIndex()), drawX, drawY);

								if (this.player.getItemWeapon() != null) {
									g.drawImage(listEquipGraphics.get(1), drawX, drawY);
								}
								if(this.player.getItemHelmet() != null) {
									g.drawImage(listEquipGraphics.get(0), drawX, drawY);
								}
								
								if(this.player.getItemArmor() != null) {
									g.drawImage(listEquipGraphics.get(3), drawX, drawY);
								}
								if(this.player.getItemShield() != null) {
									g.drawImage(listEquipGraphics.get(2), drawX, drawY);
								}
								// g.drawImage(swordSprite, drawX, drawY);
								// g.drawImage(helmetSprite, drawX, drawY);
								// g.drawImage(armorSprite, drawX, drawY);
								// g.drawImage(shieldSprite, drawX, drawY);

								g.setColor(Color.white);
								g.setFont(combatMsgFont);
								g.drawString(combatMsg, drawX, drawY);
							}

							// Cursor
							if (mouseX == x && mouseY == y) {

								g.setColor(Color.white);

							}
						}
					}
				}
			}

		} else {

			// Inventory

			int i = 0;
			for (int x = 0; x < 10; x++) {
				for (int y = 0; y < 10; y++) {

					if (x == inventoryX && y == inventoryY) {
						g.setColor(Color.white);
						g.fillRect(x * tileSize + xOffset, y * tileSize + yOffset, tileSize, tileSize);
					} else {
						g.setColor(Color.gray);
						g.drawRect(x * tileSize + xOffset, y * tileSize + yOffset, tileSize, tileSize);
					}

					if (this.player.getListItems().size() > i) {
						if (this.player.getListItems().get(i) != null) {
							if (this.player.getListItems().get(i).isInUse()) {
								g.setColor(Color.orange);
								g.drawRect(x * tileSize + xOffset, y * tileSize + yOffset, tileSize, tileSize);
							}
							g.drawImage(listItemGraphics.get(this.player.getListItems().get(i).getItemType().getSpriteId()), x * tileSize + xOffset, y
									* tileSize + yOffset);
						}
					}
					i++;
				}
			}

			if (selectedItemIndex != -1 && selectedItemIndex < this.player.getListItems().size()) {
				g.setColor(Color.white);
				if(this.player.getListItems().get(selectedItemIndex) != null) { 
					g.drawString(this.player.getListItems().get(selectedItemIndex).getItemType().getName(), 450, 20);
					g.drawString(this.player.getListItems().get(selectedItemIndex).getItemType().getDescription(), 450, 35);
				}
			}

		}

		if (this.player != null) {
		/*	g.drawString("D: " + this.player.getCurLevelIndex() + " L: " + this.player.getLevel() + " HP: " + this.player.getCurHp() + " MP: "
					+ this.player.getCurMp() + " XP: " + this.player.getExperience() + " / " + this.player.getMaxExperience(), 10, 560);*/
		}

		// DEBUG TEXT
		if (debug) {
			g.setColor(Color.white);
			g.drawString("DEBUG | map#" + currentLevel.getRoomNumber() + " | exp: " + this.player.getExperience() + " | items: "
					+ this.player.getListItems().size() + " | level: " + this.player.getLevel(), 10, 25);
		}
		
		//--LIFE--BAR--
		if(this.player != null) {
			
			if(this.player.getPercentHp() > 90) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(0), 170, 560);
				g.drawImage(listUiGraphics.get(0), 205, 560);
				g.drawImage(listUiGraphics.get(0), 240, 560);
			} else if(this.player.getPercentHp() > 80 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(0), 170, 560);
				g.drawImage(listUiGraphics.get(0), 205, 560);
				g.drawImage(listUiGraphics.get(1), 240, 560);
			} else if(this.player.getPercentHp() > 70 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(0), 170, 560);
				g.drawImage(listUiGraphics.get(0), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 60 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(0), 170, 560);
				g.drawImage(listUiGraphics.get(1), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 50 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(0), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 40 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(1), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 30 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(0), 135, 560);
				g.drawImage(listUiGraphics.get(2), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 20 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(1), 135, 560);
				g.drawImage(listUiGraphics.get(2), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 10 ) {
				g.drawImage(listUiGraphics.get(0), 100, 560);
				g.drawImage(listUiGraphics.get(2), 135, 560);
				g.drawImage(listUiGraphics.get(2), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else if(this.player.getPercentHp() > 0 ) {
				g.drawImage(listUiGraphics.get(1), 100, 560);
				g.drawImage(listUiGraphics.get(2), 135, 560);
				g.drawImage(listUiGraphics.get(2), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			} else {
				g.drawImage(listUiGraphics.get(2), 100, 560);
				g.drawImage(listUiGraphics.get(2), 135, 560);
				g.drawImage(listUiGraphics.get(2), 170, 560);
				g.drawImage(listUiGraphics.get(2), 205, 560);
				g.drawImage(listUiGraphics.get(2), 240, 560);
			}
		}
		
		//--MP-BAR
		g.drawImage(listUiGraphics.get(6), 285, 560);
		g.drawImage(listUiGraphics.get(7), 320, 560);
		g.drawImage(listUiGraphics.get(8), 355, 560);
		g.drawImage(listUiGraphics.get(8), 390, 560);
		g.drawImage(listUiGraphics.get(8), 425, 560);
		
		//--EXP-BAR
		g.drawImage(listUiGraphics.get(9), 470, 560);
		g.setColor(Color.gray);
		g.setFont(levelFont);
		g.drawString(this.player.getLevel()+"", 505, 560);
		
		if(this.player.getPercentExperience() > 90) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(3), 625, 560);
			g.drawImage(listUiGraphics.get(3), 660, 560);
			g.drawImage(listUiGraphics.get(3), 695, 560);
		} else if(this.player.getPercentExperience() > 80) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(3), 625, 560);
			g.drawImage(listUiGraphics.get(3), 660, 560);
			g.drawImage(listUiGraphics.get(4), 695, 560);
		} else if(this.player.getPercentExperience() > 70) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(3), 625, 560);
			g.drawImage(listUiGraphics.get(3), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 60) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(3), 625, 560);
			g.drawImage(listUiGraphics.get(4), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 50) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(3), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 40) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(4), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 30) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(3), 590, 560);
			g.drawImage(listUiGraphics.get(5), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 20) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(4), 590, 560);
			g.drawImage(listUiGraphics.get(5), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 10) {
			g.drawImage(listUiGraphics.get(3), 555, 560);
			g.drawImage(listUiGraphics.get(5), 590, 560);
			g.drawImage(listUiGraphics.get(5), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else if(this.player.getPercentExperience() > 0) { 
			g.drawImage(listUiGraphics.get(4), 555, 560);
			g.drawImage(listUiGraphics.get(5), 590, 560);
			g.drawImage(listUiGraphics.get(5), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		} else {
			g.drawImage(listUiGraphics.get(5), 555, 560);
			g.drawImage(listUiGraphics.get(5), 590, 560);
			g.drawImage(listUiGraphics.get(5), 625, 560);
			g.drawImage(listUiGraphics.get(5), 660, 560);
			g.drawImage(listUiGraphics.get(5), 695, 560);
		}
		
		
		

	}
}
